<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'普通货主列表'),
	array('op'=>'vip','title'=>'VIP会员列表'),
	array('op'=>'black','title'=>'黑名单'),	
);
$cztabs=array(
	array('op'=>'chezhu','title'=>'车主列表'),
	array('op'=>'edit','query'=>'type=1','title'=>'添加车主'),
);
$zxtabs=array(
	array('op'=>'zhuanxian','title'=>'专线列表'),
	array('op'=>'edit','query'=>'type=2','title'=>'添加专线'),
);
$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
if($_RQ['op']=='list'){
	$params=array('type'=>0);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=0;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wuliu_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'LOGO','type'=>'image'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'member_types'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员ID','type'=>'string'),
		)
	);
	$return['member_types']=$this->member_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='vip'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=1;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wuliu_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'money_get','title'=>'获得打赏总金额','type'=>'string'),
			array('name'=>'money','title'=>'可提现金额','type'=>'string'),
			array('name'=>'viptime','title'=>'会员到期时间','type'=>'time'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='black'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=1;
	$params['isvip']=1;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wuliu_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'money_get','title'=>'获得打赏总金额','type'=>'string'),
			array('name'=>'money','title'=>'可提现金额','type'=>'string'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='chezhu'){
	$params=array('type'=>1);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=0;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wuliu_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$cztabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'LOGO','type'=>'image'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'member_types'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员ID','type'=>'string'),
		)
	);
	$return['member_types']=$this->member_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='zhuanxian'){
	$params=array('type'=>2);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=0;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wuliu_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$zxtabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'LOGO','type'=>'image'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'type','title'=>'LOGO','type'=>'radio','options'=>'member_types'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员ID','type'=>'string'),
		)
	);
	$return['member_types']=$this->member_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$type=intval($_RQ['type']);
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_wuliu_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['lat_lng']=json_decode($item['lat_lng'],true);
		$item['pcd']=json_decode($item['pcd'],true);
		$item['xianlus']=json_decode($item['xianlus'],true);
		$item['images']=json_decode($item['images'],true);
	}else{
		$item=array('type'=>$type);
	}
	$return['item']=$item;
	$tabs=$type==1?$cztabs:$zxtabs;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>$tabs,
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'title','title'=>'车主名称','type'=>'string','show'=>array('type'=>1)),
					array('name'=>'title','title'=>'公司名称','type'=>'string','show'=>array('type'=>2)),
					array('type'=>'choose','name'=>'mid','title'=>'绑定用户','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
					array('name'=>'logo','title'=>'封面LOGO','type'=>'image'),
					array('name'=>'desc','title'=>'用户介绍','type'=>'text'),
					array('name'=>'pcd','title'=>'所属区域','type'=>'pcd'),
					array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
					array('name'=>'address','title'=>'详细地址','type'=>'string'),
					array('name'=>'lat_lng','title'=>'经纬度','type'=>'lat_lng'),
					array('name'=>'chepai','title'=>'车牌号','type'=>'string','show'=>array('type'=>1)),
					array('name'=>'cheimg','title'=>'货车前照','type'=>'image','show'=>array('type'=>1)),
					array('name'=>'zhizhao','title'=>'营业执照','type'=>'image','show'=>array('type'=>2)),
					array('name'=>'zhuanxianimg','title'=>'门店照片','type'=>'image','show'=>array('type'=>2)),
					array('name'=>'images','title'=>'详情幻灯片','type'=>'images'),
					array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch'),
				)
			),
			array(
				'title'=>'线路设置',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'xianlus',
							'add_tip'=>'添加线路（线路是双向的）',
								'list'=>array(
									array('type'=>'string','name'=>'fromcity','title'=>'出发地'),
									array('type'=>'string','name'=>'tocity','title'=>'目的地'),
								),
								'details'=>array(
									array('type'=>'string','name'=>'fromcity','title'=>'出发地','help'=>'填写城市名'),
									array('type'=>'string','name'=>'tocity','title'=>'目的地','help'=>'填写城市名'),
								)
						),
					)
			),
			array(
				'title'=>'价格设置',
					'list'=>array(
						array('type'=>'string_two','title'=>'重货价格','title1'=>'纯重价格','name1'=>'wprice1','unit1'=>'元/吨','title2'=>'重货价格','name2'=>'wprice2','unit2'=>'元/吨'),
						array('type'=>'string_two','title'=>'轻货价格','title1'=>'纯抛价格','name1'=>'vprice1','unit1'=>'元/方','title2'=>'纯抛价格','name2'=>'vprice2','unit2'=>'元/方'),
						array('type'=>'unitstring','name'=>'jprice','title'=>'机械价格','unit1'=>'元/吨'),
					)
			),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	if(!$postdata['title']){
		exi('请填写名称！','error');
	}
	if(!$postdata['logo']){
		exi('请填写LOGO！','error');
	}
	if(!$postdata['mid']){
		exi('请绑定会员！','error');
	}
	$pcd = $postdata['pcd'];
	if($type==1){
		if(!$postdata['chepai']){
			exi('请先设置车牌！','error');
		}
		if(!$postdata['cheimg']){
			exi('请先设置车照片！','error');
		}
	}
	if($type==2){
		if(!$postdata['zhizhao']){
			exi('请先设置营业执照！','error');
		}
		if(!$postdata['zhuanxianimg']){
			exi('请先设置门店照片！','error');
		}
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'logo'=>trim($postdata['logo']),
		'desc'=>trim($postdata['desc']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'lat_lng'=>ijson_encode($postdata['lat_lng']),
		'xianlus'=>ijson_encode($postdata['xianlus']),
		'images'=>ijson_encode($postdata['images']),
		'mobile'=>trim($postdata['mobile']),
		'address'=>trim($postdata['address']),
		'chepai'=>trim($postdata['chepai']),
		'cheimg'=>trim($postdata['cheimg']),
		'zhizhao'=>trim($postdata['zhuanxianimg']),
		'zhuanxianimg'=>trim($postdata['zhuanxianimg']),
		'mid'=>intval($postdata['mid']),
		'type'=>intval($postdata['type']),
		'wprice1'=>intval($postdata['wprice1']),
		'wprice2'=>intval($postdata['wprice2']),
		'vprice1'=>intval($postdata['vprice1']),
		'vprice2'=>intval($postdata['vprice2']),
		'jprice'=>intval($postdata['jprice']),
	);
	if($id){
		pdo_update('jy_wuliu_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_wuliu_member',$data);
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_wuliu_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的用户！','error');
	}
	$post=get_postdata();
	if(isset($post['isblack'])){
		pdo_update('jy_wuliu_member',array('isblack'=>intval($post['isblack'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='shenhe'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要审核的用户！','error');
	}
	$post=get_postdata();
	if(isset($post['isblack'])){
		pdo_update('jy_wuliu_member',array('isblack'=>intval($post['isblack'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}